﻿@model Retete.ViewModels.BonConsumViewModel
@{
    ViewBag.Title = "Vanzari";
}

<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("#Data").datepicker({ dateFormat: 'mm/dd/yy' });
    });

    function filtreaza() {
        form.submit();
    }
    function exportExcel() {
        ExportExcel.value = true;
        form.submit();
    }
</script>

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "form", name = "form" }))
{
    for (int i = 0; i < @Model.Categorii.Count; i++)
    {
        @Html.HiddenFor(element => element.Categorii[i])
    }
    
    <table style="width: 100%">
        <tr>
            <td style="width: 190px; vertical-align: top; border-right-style: dashed; border-right-color: #CFCFCF; border-right-width: 1px;">
                <fieldset>
                    <legend>Activitati</legend>

                    <p class="toolbox"><a href="javascript:exportExcel()">Tiparire</a></p>
                </fieldset>
            </td>
            <td style="vertical-align: top;">
                <fieldset>
                    @Html.HiddenFor(model => model.ExportExcel)
                    <legend>Configurare raport</legend>

                    <p>
                        @Html.LabelFor(element => element.Data, "Data:")
                        @Html.TextBoxFor(element => element.Data, new { style = "width: 194px" })
                    </p>

                    <p>
                        @Html.LabelFor(element => element.Categorie, "Categorie:")
                        @Html.DropDownListFor(element => element.Categorie, new SelectList(Model.Categorii), new { style = "width: 200px" })
                    </p>

                    <p>
                        @Html.LabelFor(element => element.Data, " ")
                        <a onclick="filtreaza()" href="#">Genereaza raport</a>
                    </p>
                </fieldset>

                <fieldset>
                    <legend>Bon de consum</legend>

                    <table class="grid">
                        <thead>
                            <tr>
                                <th style="width: 70px">Cod</th>
                                <th style="width: 100px">Categorie</th>
                                <th>Produs</th>
                                <th style="width: 70px">Cantitate</th>
                                <th style="width: 70px">Pret</th>
                                <th style="width: 139px">Valoare</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (@Model.Elemente != null)
                            {
                                for (int i = 0; i < Model.Elemente.Count; i++)
                                {
                                    <tr>
                                        <td>
                                            @Model.Elemente[i].Cod
                                            @Html.HiddenFor(element => element.Elemente[i].Cod)
                                        </td>
                                        <td>
                                            @Model.Elemente[i].Categorie
                                            @Html.HiddenFor(element => element.Elemente[i].Categorie)
                                        </td>
                                        <td>
                                            @Model.Elemente[i].Nume
                                            @Html.HiddenFor(element => element.Elemente[i].Nume)
                                            @Html.HiddenFor(element => element.Elemente[i].UnitateMasura)
                                        </td>
                                        <td>
                                            @Model.Elemente[i].Cantitate.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)
                                            @Html.HiddenFor(element => element.Elemente[i].Cantitate)
                                        </td>
                                        <td>
                                            @Model.Elemente[i].PretCumparare.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)
                                            @Html.HiddenFor(element => element.Elemente[i].PretCumparare)
                                        </td>
                                        <td>
                                            @Model.Elemente[i].ValoareCumparare.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture)
                                            @Html.HiddenFor(element => element.Elemente[i].ValoareCumparare)
                                        </td>
                                    </tr>
                                }
                            
                                <tr class="totals">
                                    <td></td>
                                    <td></td>
                                    <td>Total:</td>
                                    <td></td>
                                    <td></td>
                                    <td>@Model.Elemente.Sum(element => element.ValoareCumparare).ToString("0.00")</td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </fieldset>
            </td>
        </tr>
    </table>
}